def poz(j):
    z = True
    for w in range(2, int(j ** 0.5)+1):
        if j % w == 0:
            z = False
            break
    return z

y = int(input())
if y < 1000 or y > 9999:
    print(0)
else:
    lmno = str(y)
    pq = 0
    for r in range(len(lmno)):
        for k in range(r+1, len(lmno)+1):
            bro = int(lmno[r:k])
            if poz(bro):
                pq = max(pq, bro)
    print(pq)

